﻿using System;
using System.IO.IsolatedStorage;
using System.IO;
using System.Globalization;


namespace
#if WINDOWS_PHONE
    PServiceBus.WindowsPhone
#else
 PServiceBus.Silverlight
#endif 
{
    internal static class LocalStorage {
        public static void Set<T>(T value, string key) {
            IsolatedStorageSettings.ApplicationSettings[key] = value;
        }

        public static T Get<T>(string key) {
            var hasData = IsolatedStorageSettings.ApplicationSettings.Contains(key);
            return hasData ? (T)Convert.ChangeType(IsolatedStorageSettings.ApplicationSettings[key], typeof(T), CultureInfo.CurrentCulture)
                : default(T);
        }

        public static void Delete(string key) {
            IsolatedStorageSettings.ApplicationSettings.Remove(key);
        }
    }
}
